package com.cjj.common.entity.dto.excel;

import lombok.*;

import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @ClassName SheetDTO
 * @Date 2021/09/17 15:34:05
 * @Created by ccc-j
 * @email ccc-ju@outlook.com
 */

@Data
@AllArgsConstructor
@NoArgsConstructor
@Setter
@Getter
@Builder
public class SheetDTO {

    private static final long serialVersionUID = 1L;

    /*
    * sheet页名称
    */
    private String sheetName;

    /** 字段和别名，如果使用这个，properties 和 titles可以不用处理 */
    private Map<String, String> fieldAndAlias;

    /** 字段 */
    private String[] properties;

    /** 标题/别名 */
    private String[] titles;

    /** 列宽 */
    private Integer[] columnWidth;

    /** 数据集 */
    private Collection<?> collection;

    /**
     * 需要反射的类
     */
    private Class clazz;

    public Map<String, String> getFieldAndAlias() {
        if (fieldAndAlias == null) {
            this.fieldAndAlias = new LinkedHashMap<String, String>();
            for (int i = 0; i < this.properties.length; i++) {
                fieldAndAlias.put(this.properties[i], this.titles[i]);
            }
        }
        return fieldAndAlias;
    }
}
